import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Index',
    component: () => import('@/views/IndexView.vue'), // 使用@别名简化路径
    meta: {
      title: '首页'
    }
  },
  {
    path: '/extcode/:code', // 路径小写，保持URL一致性
    name: 'Extcode',
    component: () => import('@/views/Extcodeview.vue'), // 修正文件名大小写
    meta: {
      title: '任务管理'
    }
  },
  {
    path: '/upload',
    name: 'Upload',
    component: () => import('@/views/Uploadview.vue'), // 修正文件名大小写
    meta: {
      title: 'AI绘画'
    }
  },
  {
    path: '/image-to-prompt',
    name: 'ImageToPrompt',
    component: () => import('@/views/ImageToPrompt.vue'),
    meta: {
      title: '图生文'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = `${to.meta.title || 'AI绘画'} - Mai-Ya`
  next()
})

export default router